package com.itany.corejava.code08_常用类.object类;

import java.util.Objects;

/**
 * @author 石小俊
 * 2024年07月19日 9:19
 */
public class Person implements Cloneable {

    private String name;
    private int age;
    private Address address;

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }
//@Override
    //public boolean equals(Object obj) {
    //    if (obj.getClass() == Person.class) {
    //        Person person = (Person) obj;
    //        return this.age == person.getAge() && this.name.equals(person.getName());
    //    }
    //    return false;
    //}


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age &&
                Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    //@Override
    //public String toString() {
    //    return "{name = " + name + ", age = " + age + "}";
    //}


    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", address=" + address +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    protected void finalize() throws Throwable {
        System.out.println("**************正在回收垃圾**************");
        super.finalize();
    }
}
